package com.yzy.event;

import org.apache.commons.lang3.SystemUtils;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Correlation;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.beans.factory.annotation.Value;

import java.net.InetAddress;

/**
 * @author yangzhenyu
 * @version 1.0
 * @description:
 * @date 2022/7/14 10:00
 */
public class MqMessageHeaderProcessor implements MessagePostProcessor {
    public static final String type = "gray";
    @Value("${spring.application.name}")
    String applicationName;

    public MqMessageHeaderProcessor() {
    }

    public Message postProcessMessage(Message message) throws AmqpException {
        message.getMessageProperties().setHeader("msgSender", this.applicationName);
        message.getMessageProperties().setHeader("senderType", type);
        message.getMessageProperties().setHeader("msgSendFrom", getHostName());


        return message;
    }
    public  String getHostName(){
        try {
            return InetAddress.getLocalHost().getHostName();

        }catch (Exception e){
             //获取主机错误
            return "";
        }
    }
}
